package dao;

import utils.DBHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class QuerylistDao {

    public Map<String,Object> list (Integer id, int page,int size){


        String sql="select p.image, o.date,p.product,t.price,a.site,o.`status` from `order` o ,users u,plist p,orderitem t,address a \n" +
                "where o.aid=a.id and o.uid=u.id and t.oid=o.id and t.pid=p.id and o.`status`=1 and o.uid=? ";
        long total = DBHelper.count(sql,id);
        System.out.println(total);
        sql+=" limit ?,?";
        List<Map<String, Object>> data = DBHelper.selectListMap(sql, id,page,size);
        System.out.println(data);
        Map<String,Object> res = new HashMap<>();
        res.put("total", total);
        res.put("data", data);
        return res;
    }

    public void setdefault(Integer aid,Integer id){
        String sql="update users set aid = ? where id = ?";
        DBHelper.update(sql,aid,id);
    }
    public Map<String,Object> queryaid(String site,String name,String  telphone){
        String sql="select id from address where name = ? and telphone =? and site = ?";
        return DBHelper.selectOneMap(sql,name,telphone,site);
    }
}
